fn main() {
    println!("Hello, world!");
    // 1.1
    greet_world();
    // 1.2
    complicate_test();

    // 2.1
    
}

// test 1.4
fn greet_world() {
    let southern_germany = "Grüß Gott!";
    let chinese: &str = "世界，你好";
    let english = "World, Hello";
    let regions = [southern_germany, chinese, english];
    for region in regions.iter() {
        println!("{}", &region);
    }
}

// test 1.4
fn complicate_test() {
    let penguin_data = "\
    common name, length(cn)
    Little penguin, 33
    Fiordland penguin, 60
    Invalid, data
    ";
    let records = penguin_data.lines();
    for (i, record) in records.enumerate() {
        if i == 0 || record.trim().len() == 0 {
            continue;
        }
        // 声明一个fields变量，类型为Vec, 可伸缩集合类型，可以认为是一个动态数组
        let fields: Vec<_> = record.split(',').map(|field| field.trim()).collect();
        if cfg!(debug_assertions) {
            eprintln!("debug:{:?} -> {:?}", record, fields);
        }
        let name = fields[0];
        if let Ok(length) = fields[1].parse::<f32>(){
            println!("{}, {}cm", name, length);
        }
    }
}
